<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>商品添加管理</h1>
<div>
    <input type="text" v-model="p.title" placeholder="商品名称"><br>
    <input type="text" v-model="p.price" placeholder="商品价格"><br>
    <input type="text" v-model="p.saleCount" placeholder="商品库存"><br>
    <input type="button" value="添加" @click="add()">
    <input type="button" value="返回首页" @click="back()">
</div>
<script src="js/vue.js"></script>
<script src="js/axios.min.js"></script>
<script>
    let v = new Vue({
        el:"div",
        data:{
            p:{
                title:null,
                price:null,
                saleCount:null,
            }
        },
        methods:{
            add(){
                axios.post("/insert",v.p).then(function (response){
                    if (response.data==1){
                        alert("请输入完整信息添加商品!")
                        location.reload();
                        return;
                    }
                    alert("添加完成!")
                    location.reload();
                })
            },
            back(){
                location.href='/';
            }
        }
    })
</script>
</body>
</html>